package com.yonyou.rabbitmq.common.enums;

import org.springframework.util.StringUtils;

import java.util.Objects;

public enum SiteEnum implements BaseEnum{

    GF("0000","gf"),
    ZW("0001","zw");

    private final String key;
    private final String value;

    SiteEnum(String key, String value) {
        this.key = key;
        this.value = value;
    }

    public static String getValue(String code) {
        if (StringUtils.isEmpty(code)) {
            return null;
        }
        SiteEnum item = getByKey(code);
        if (item == null) {
            return null;
        }
        return item.getValue();
    }

    public static SiteEnum getByKey(String code) {
        for (SiteEnum item : values()) {
            if (Objects.equals(item.getKey(), code)) {
                return item;
            }
        }
        return null;
    }

    public static SiteEnum getByValue(String value) {
        for (SiteEnum item : values()) {
            if (Objects.equals(item.getValue(), value)) {
                return item;
            }
        }
        return null;
    }

    public static String getKey(String value){
        SiteEnum byValue = getByValue(value);
        if(Objects.isNull(byValue)){
            return null;
        }

        return byValue.getKey();
    }

    @Override
    public String getKey() {
        return key;
    }

    @Override
    public String getValue() {
        return value;
    }
}
